package com.csq.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author ercai
 * @date 2019/7/26 - 9:39
 */
@Component
@Aspect
@Slf4j
public class AnnotateInterceptor {

    @Pointcut("execution(* com.csq.service..* (..))")
    public void userServiceAnnotate(){

    }

    @Around(value = "userServiceAnnotate()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("环绕前置通知");
        long startTime = System.currentTimeMillis();
        Object proceed = proceedingJoinPoint.proceed();
        long endTime = System.currentTimeMillis() - startTime;
        String name = proceedingJoinPoint.getClass().getName();
        log.info(name+"类，调用了"+ proceedingJoinPoint.getSignature().getName()+"方法");
        log.info("用时"+ endTime/1000.0);
        log.info("环绕后置通知");
        return proceed;
    }

    @AfterReturning(value = "userServiceAnnotate()",returning = "result")
    public void after(String result){

        log.info("返回值为"+result);
    }
}
